package com.ccf.business.etl.flow;

import com.alibaba.fastjson.JSON;
import com.component.api.constants.ComponentConstants;
import com.component.api.model.dto.MapColumnDTO;
import com.component.api.model.dto.MergeColumnDTO;
import com.common.utils.tool.StringUtil;
import com.common.model.exception.ParamFomatException;

import java.util.List;
import java.util.Map;

/**
 * 描述：
 *
 * @author xianggj
 * @Date 2021/11/30 15:16
 **/
public class GatherMergeParamHandler extends ParamHandler {

    @Override
    protected Map<String, String> finishingParam() {
        Map<String, String> params = getParams();
        String columns = params.get(ComponentConstants.IN_COLUMNS);
        if (StringUtil.isJsonBlank(columns)){
            throw new ParamFomatException("缺少配置参数columns");
        }
        try {
            List<MergeColumnDTO> mergeColumnDTOS = JSON.parseArray(columns, MergeColumnDTO.class);
            params.put(ComponentConstants.COLUMNS, JSON.toJSONString(mergeColumnDTOS));
        } catch (Exception e) {
            e.printStackTrace();
            throw new ParamFomatException("参数格式错误");
        }
        //这里获取的是节点信息
        params.put(ComponentConstants.TABLE_NAME, params.get(ComponentConstants.TABLE_NAME));
        return params;
    }
}
